import { fileURLToPath, URL } from 'node:url'

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueSetupExtend from "vite-plugin-vue-setup-extend";

// https://vitejs.dev/config/
export default (({mode}) => {
  const env = loadEnv(mode, process.cwd());
  return defineConfig({
    // base: env.VITE_CDN_DOMAIN,
    experimental:{
      renderBuiltUrl(fileName,{hostId,hostType,type}){
        console.log(fileName,hostId,hostType,type);
        if(type === 'asset'){
          return env.VITE_CDN_DOMAIN+fileName
        }
        
      }
    },
    plugins: [
      vue(), vueSetupExtend()
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      host: '0.0.0.0',
      port: 5177
    }
  })
})
